import 'package:flutter/material.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import '../home/home_page.dart';
import '../discovered/discovered_page.dart';
import '../../function/routes/app_route_manager.dart';

/// 主页面
class MainScreen extends StatefulWidget {
  const MainScreen({super.key});

  @override
  State<MainScreen> createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    // 页面列表
    final pages = [const HomePage(), const DiscoveredPage()];

    return Scaffold(
      extendBody: true,
      body: IndexedStack(index: currentIndex, children: pages),
      bottomNavigationBar: Container(
        margin: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 44.h),
        width: double.infinity,
        height: 60.h,
        decoration: BoxDecoration(
          color: const Color(0xFFFF8A3C),
          borderRadius: BorderRadius.circular(30.r),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            // 首页图标
            GestureDetector(
              onTap: () => setState(() => currentIndex = 0),
              child: Container(
                padding: EdgeInsets.all(12.w),
                child: Image.asset(
                  'assets/images/home.png',
                  width: 36.w,
                  height: 36.w,
                  color:
                      currentIndex == 0
                          ? Colors.white
                          : const Color(0xFF854D12),
                ),
              ),
            ),

            // Release按钮
            GestureDetector(
              onTap: () => AppRouteManager.navigateToRelease(),
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
                decoration: BoxDecoration(
                  color: const Color(0xFF854D12),
                  borderRadius: BorderRadius.circular(4.r),
                ),
                child: Text('Release')
                    .fontSize(16.sp)
                    .textColor(Colors.white)
                    .fontWeight(FontWeight.w600),
              ),
            ),

            // 发现页图标
            GestureDetector(
              onTap: () => setState(() => currentIndex = 1),
              child: Container(
                padding: EdgeInsets.all(12.w),
                child: Image.asset(
                  'assets/images/discovered.png',
                  width: 36.w,
                  height: 36.w,
                  color:
                      currentIndex == 1
                          ? Colors.white
                          : const Color(0xFF854D12),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
